package com.msl.base.controller;

import com.msl.base.pojo.Label;
import com.msl.base.service.LabelService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ProjectName: tensquare_parent03
 * @Package: com.msl.base.controller
 * @ClassName: LabelController
 * @Author: Messi
 * @Date: 2020/7/30 21:31
 * @Version: 1.0
 */
@RestController
@RequestMapping("/label")
public class LabelController {
    @Autowired
    private LabelService labelService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public Result findAll(){
        List<Label> all = labelService.findAll();
        return new Result(true, StatusCode.OK,"查询成功",all);
    }

    /**
     * 根据id查询标签
     * @param labelId
     * @return
     */
    @GetMapping("/{labelId}")
    public Result findById(@PathVariable String labelId){
        Label byId = labelService.findById(labelId);
        return new Result(true,StatusCode.OK,"查询成功",byId);
    }

    /**
     * 添加标签
     * @param label
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Label label){
        labelService.add(label);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /**
     * 根据id修改标签
     * @param label
     * @param labelId
     * @return
     */
    @PutMapping("/{labelId}")
    public Result update(@RequestBody Label label,@PathVariable String labelId){
        label.setId(labelId);
        labelService.update(label);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /**
     * 删除
     * @param labelId
     * @return
     */
    @DeleteMapping("/{labelId}")
    public Result delete(@PathVariable String labelId){
        labelService.deleteById(labelId);
        return new Result(true,StatusCode.OK,"删除成功");
    }




}
